package com.eryos.android.cigarettecounter.charts;

/**
 * Project :  CigaretteCounter
 * Author :   Olivier Combe 
 * URL :      http://eryos.fr/CigaretteCounter/
 *
 * Copyright (C) 2011 - Olivier Combe 
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */


public class HistoChart extends Chart {

	/** *************** Static Variables *************** **/	
	/* Specific Chart arguments */
	private int maxVal 		= 12;
	private int YMaxRange 	= Math.round(new Float(1.2*maxVal));
	
	private String barColor 	= "A2C180";
	private String XAxisLabel 	= "";
	
	public HistoChart() {
		type 		= "bvg";
	}
	
	public String generateURL(int _width, int _height){    	

		String gTitle = "";
		String gTitleFont = "";
		String gBackground 	= "chf=bg,s,"+bgColor;
		String gXLabel 		= "&chxl=1:|"+XAxisLabel;
		String gScale 		= "&chxr=0,0,"+YMaxRange;
		String gLegendColor = "&chxs=0,"+axisColor+","+textSize+",0,l,"+axisColor+"|1,"+axisColor+","+textSize+",0,l,"+axisColor+"";
		String gVisibleAxis = "&chxt=y,x";
		String gUnknown2 	= "&chbh=a,5,10";
		String gSize 		= "&chs="+_width+"x"+_height;
		String gChartType 	= "&cht="+type;
		String gDataColor 	= "&chco="+barColor;
		String gMaxYValue 	= "&chds=0,"+YMaxRange;
		String gData 		= "&chd=t:"+data;
		String gLegend 		= "&chdlp=t";
		String gUnknown1 	= "&chg=0,10";
		String gValueLegend = "&chm=N,ffffff,0,,10";
		
		String URL = ROOT_URL +
		gBackground  +
		gXLabel  +
		gScale  +
		gLegendColor  +
		gVisibleAxis  +
		gUnknown2  +
		gSize  +
		gChartType  +
		gDataColor  +
		gMaxYValue  +
		gData  +
		gLegend  +
		gUnknown1  +
		gTitle +
		gTitleFont +
		gValueLegend; 
		
		return URL;
	}

	public void setMaxVal(int maxVal) {
		this.maxVal = maxVal;
		YMaxRange = Math.round(new Float(1.2*maxVal));
	}

	public void setBarColor(String barColor) {
		this.barColor = barColor;
	}

	public void addColumnLabel(String label){
		if ( XAxisLabel == null || XAxisLabel.length() == 0 )
			XAxisLabel = label;
		else
			XAxisLabel = XAxisLabel + Chart.LABEL_SEPARATOR + label;
	}

}
